// https://leetcode.cn/problems/koko-eating-bananas/
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

class Solution {
public:
    int minEatingSpeed(vector<int>& piles, int h) {
		int right = *max_element(piles.begin(), piles.end());
		int left = 1;
		int mid = 0;
		while(left < right){
			mid = (left + right)/2;
			int sum = 0;
			for(int i = 0; i < piles.size(); i++){
				sum += piles[i]%mid == 0 ? piles[i]/mid : piles[i]/mid+1;
			}
			if(sum > h){
				left = mid+1;
			}else{
				right = mid;
			}
			cout << "left:" << left << ",right:" << right << endl;
		}
		if(left == right) return left;
		return mid;
    }
};

int main(){
	vector<int> nums = {30,11,23,4,20};
	int h = 5;
	Solution so;
	int res = so.minEatingSpeed(nums, h);
	cout << res << endl;
	return 0;
}